<template id="doudle_total">
	<div class="doudle_total">

		<div class="doudle_main" v-for="(item,index) in todos" :key="index" v-show="index">

			<div class="doudle_main_top"><img src="../../assets/images/my_order/my_order_15.png" />
				<img src="../../assets/images/main/doudle_del.png"  @click.stop="total(index,item.pay_issucess,item.booking_id)" /></div>
			<div class="doudle_main_dl">
				<div class="doudle_dl">

					<dl>
						
							<dt><img src="../../assets/images/class/about_coach.png"/></dt>
							<dd>
								<p>教练姓名：{{item.coach_name}}</p>
								<p>预约课程：{{item.class_name}}</p>
								<p>预约时间:{{item.create_time | formatDate}}</p>
							</dd>
					
					</dl>
				</div>
			</div>

			<div class="doudle_money">
				<div class="doudle_neth">
					<span>实付款: </span>
					<font>￥</span>{{item.price}}</font>
				</div>
			</div>

			<div class="doudle_detail">
				<div class="doudle_hear">
					<router-link :to="{path:'/order_details',query:{ bookingid:item.booking_id}}"><button>订单详情</button></router-link>
					<router-link :to="{path:'/appointment_coach',query:{coachid:item.coach_id}}"><button>再次预约</button></router-link>
				</div>
			</div>

		</div>

	</div>
</template>

<script>
	export default {
		data() {

			return {
				todos:[],
				bookingid:'',
				index:true
			}

		},
		components: {},
		created() {
         
         	//let SESSION_ID = JSON.parse(window.sessionStorage.getItem('SESSION_ID'));
			 var SESSION_ID=JSON.parse(window.localStorage.getItem('sessiond'))
				let obj = {
					//请求的参数
					userid: SESSION_ID.user.id,
					sessionid: SESSION_ID.sessionid,	
					bookingid:this.bookingid,
					
				};
				let _this = this
				let qs = require('qs');
			this.$axios.post("http://yogahome.top/Scanning/user/findAllBookingByUserId", qs.stringify(obj), {
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded'
					}
					//重写headers 请求头  qs.stringify(json对象) 把对象转化为字符串 
				}).then(function(response) {

					_this.todos = response.data.data;
					return _this.todos.reverse();

				  console.log(_this.todos[0].pay_issucess)

				  _this.bookingid = response.data.data[0].booking_id
					
				}).catch(function(error) {
					console.log(error);
				});
		
			
		},
		filters: {
			formatDate: function(value) {
				let date = new Date(value);
				let y = date.getFullYear();
				let MM = date.getMonth() + 1;
				MM = MM < 10 ? ('0' + MM) : MM;
				let d = date.getDate();
				d = d < 10 ? ('0' + d) : d;
				let h = date.getHours();
				h = h < 10 ? ('0' + h) : h;
				let m = date.getMinutes();
				m = m < 10 ? ('0' + m) : m;
				let s = date.getSeconds();
				s = s < 10 ? ('0' + s) : s;
				return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s;
			},
		},
		methods: {
			total(index,pay_issucess,bookingid){
				console.log(pay_issucess,bookingid)
				//let SESSION_ID = JSON.parse(window.sessionStorage.getItem('SESSION_ID'));
				 var SESSION_ID=JSON.parse(window.localStorage.getItem('sessiond'))
				let obj = {
					//请求的参数
					userid: SESSION_ID.user.id,
					sessionid: SESSION_ID.sessionid,	
					bookingid:bookingid,
					
				};
				if(pay_issucess == 0 ){
						let _this = this
						let qs = require('qs');
						_this.$axios.post("http://yogahome.top/yujia/booking/cancelBooking", qs.stringify(obj), {
							headers: {
								'Content-Type': 'application/x-www-form-urlencoded'
							}
							//重写headers 请求头  qs.stringify(json对象) 把对象转化为字符串 
						}).then(function(response) {
							console.log(response)
							if(response.data.code =='1')
							alert('取消成功')
							//_this.index = false
						setTimeout(() => {
                         console.log($(".doudle_total").children())
						 var arr = $(".doudle_total").children()
						 console.log(index)
						 for(var i = 0; i< arr.length;i++){
                           if(index == i)
						   console.log(i)
						   arr[i].style.display ='none'
						 }
						
						},1000)
						

						
							
						}).catch(function(error) {
							console.log(error);
						});
				}else{
   					this.$axios.post("http://yogahome.top/Scanning/user/findAllBookingByUserId", qs.stringify(obj), {
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded'
					}
					//重写headers 请求头  qs.stringify(json对象) 把对象转化为字符串 
					}).then(function(response) {
                          this.seen = false
						this.todos = response.data.data;
						
					}).catch(function(error) {
						console.log(error);
					});
				}



				
				
			}
		},

		computed: {
            
		}

	}
</script>

<style scoped>
	@import "../../assets/css/doudle_total.css";
</style>